﻿	<%@ taglib prefix='c' uri='http://java.sun.com/jsp/jstl/core'%>
	<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
	<%@ page import="com.cxx.purchasecharge.component.utils.ComponentConstants" %>

	<style type="text/css">
		#dlg-role input, #dlg-role select
		{
			width: 150px;
		}
		#dlg-role #fm-role div 
		{
			float: left;
			width: 155px;
			margin: 5px 30px;
		}
	</style>
	
	<script type="text/javascript">
		var hideAuthPanelAfterSelect = function() 
		{
			var auths = $('#dlg-role #fm-role #authority').combotree('getValues');
			$('#dlg-role #fm-role #authorities').val(auths);
		}
		var cellFormatter_roleAuthority = function(value,row,index)
		{
			var auths = '';
			if(row.authorityBeans)
			{
				if(row.authorityBeans.length >= 1) 
				{
					for(var i = 0; i < row.authorityBeans.length; i++) 
					{
						auths += (row.authorityBeans[i].name + ',');
					}
					auths = auths.substring(0, auths.length - 1);
				}
			}
			return '<span>' + auths + '</span>';
		}
		var editRoleCallback = function() 
		{
			var role = $('#dg-role').datagrid('getSelected');
			if(role) 
			{
				var auths = role.authorityBeans;
				if(auths && auths.length > 0) 
				{
					var authIds = new Array(auths.length);
					for(var i = 0; i < auths.length; i ++) 
					{
						authIds[i] = auths[i].id;
					}
					$('#dlg-role #fm-role #authority').combotree('setValues', authIds);
					hideAuthPanelAfterSelect();
				}
				
				if(role.enabled) 
				{
					$('#dlg-role #fm-role #enabled')[0].checked = true;
				}
				else 
				{
					$('#dlg-role #fm-role #enabled')[0].checked = false;
				}
				if(role.system) 
				{
					$('#dlg-role #fm-role #system')[0].checked = true;
				}
				else 
				{
					$('#dlg-role #fm-role #system')[0].checked = false;
				}
			}
		}
    </script>
	
	<table id="dg-role" title="角色管理" class="easyui-datagrid" url="<c:url value='/role/getAllModel.html' />"
		toolbar="#toolbar-role" rownumbers="true" fit="true"
		 singleSelect="true" checkOnSelect="true" selectOnCheck="false"
		fitColumns="true">
		<thead>
			<tr>
				<th data-options="field:'ck',checkbox:true"></th>
				<th data-options="field:'id',hidden:true"></th>
				<th field="name" width="50" sortable="true">角色名</th>
				<th field="enabled" width="30" sortable="true" data-options="formatter:cellFormatter_enable, align:'center'">可用</th>
				<th field="system" width="30" sortable="true" data-options="formatter:cellFormatter_enable, align:'center'">系统角色</th>
				<th field="authority" width="70" sortable="false" data-options="formatter:cellFormatter_roleAuthority, styler:cellStyler_userRole">权限</th>
				<th field="comment" width="70" sortable="false">备注</th>
			</tr>
		</thead>
	</table>
	
	<div id="toolbar-role">
		<a href="javascript:void(0)" class="easyui-linkbutton" 
			iconCls="icon-add" plain="true" onclick="newModel('#dlg-role', '新增角色', '#fm-role', '<c:url value='/role/addModel.html' />')" title="新增角色">新增角色</a> 
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-edit" plain="true" onclick="editModel('#dg-role', '#dlg-role', '编辑角色', '#fm-role', '<c:url value='/role/updateModel.html' />', editRoleCallback)" title="<spring:message code="selectOneRow" />编辑角色">编辑角色</a> 
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-remove" plain="true" onclick="destroyMultipleModel('#dg-role', '角色', '<c:url value='/role/deleteModels.html' />')" title="<spring:message code="checkOneOrMultiple" />删除角色">删除角色</a>
	</div>

	<div id="dlg-role" class="easyui-dialog"
		style="width: 800px; height: 320px; padding: 20px 5px" closed="true"
		buttons="#dlg-buttons-role" data-options="modal:true">
		<div style="width:100%;height:100%">
			<form id="fm-role" class="fm" style="margin:0 auto;padding:0px;width:650px;height:100%;" method="post" novalidate>
				<div class="fitem divHidden">
					<input id="roleId" name="id" value="0">
				</div>
				<div class="fitem">
					<label>名称:</label> 
					<input name="name" class="easyui-textbox" required="true"
					validType="myRemote['<c:url value='/role/checkExist.html' />', 'name', '#roleId']">
				</div>
				<div class="fitem">
					<label>可用:</label> 
					<input id="enabled" name="enabled" type="checkbox" style="width:30px; height:18px" />
				</div>
				<div class="fitem">
					<label>是否系统:</label> 
					<input id="system" name="system" type="checkbox" style="width:30px; height:18px" />
				</div>
				<div class="fitem">
					<label>权限:</label> 
					<input name="authority" id="authority" class="easyui-combotree"   
						data-options="url:'<c:url value='/authority/getAllModel.html' />',required:true, 
						multiple:true, checkbox:true, 
						onHidePanel:hideAuthPanelAfterSelect">
					<input name="authorities" id="authorities" type="hidden" />
				</div>
				<div class="fitem" style="width:375px;">
					<label>备注:</label> 
					<input name="comment" class="easyui-textbox" style="width:370px;">
				</div>
			</form>
		</div>
	</div>
	<div id="dlg-buttons-role">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-ok" onclick="saveModel('#dg-role', '#dlg-role', '#fm-role')"><spring:message code="save" /></a> 
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-cancel" onclick="javascript:$('#dlg-role').dialog('close')"><spring:message code="cancel" /></a>
	</div>